package com.qiyang.mq;

import com.qiyang.mq.controller.SysUser;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created on 2018/6/8.
 *
 * @author sehuaqi.
 * 描述：消息发送者
 */
@Component
public class HelloSender {

    @Autowired
    private AmqpTemplate rabbitTemplate;

    /**
     * 投递消息
     */
    public void send() {
        String context = "Hello " + new Date();

        System.out.println("Sender:" + context);

        this.rabbitTemplate.convertAndSend("hello", context);
    }

    /**
     * 投递消息
     */
    public void send(String  param) {

        String context = param + " 时间：" + new Date();

        //System.out.println("Sender:" + context);

        this.rabbitTemplate.convertAndSend("hello", context);
    }

    /**
     * 发送对象
     * @param sysUser
     */
    public void send(SysUser sysUser) {

        this.rabbitTemplate.convertAndSend("user_q", sysUser);

    }
}
